//
//  FBPayYHKView.m
//  XTXOneToOne
//
//  Created by Canny on 2018/11/13.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "FBPayYHKView.h"
#import "PayTypeSelectedButton.h"


@interface FBPayYHKView ()
@property (nonatomic,strong)UILabel * lab1;
@property (nonatomic,strong)UILabel * lab2;
@property (nonatomic,strong)UILabel * lab3;
@property (nonatomic,strong)UILabel * lab4;
@property (nonatomic,strong)UILabel * lab5;
@property (nonatomic,strong)UILabel * lab6;
@property (nonatomic,strong)UILabel * lab7;
@property (nonatomic,strong)UILabel * lab8;
@property (nonatomic,strong)UILabel * lab9;

@property (nonatomic,strong)UILabel * time;

@property (nonatomic,strong)UIImageView * simgV ;
@property (nonatomic,assign)BOOL isAgreedXieYi;



@property (nonatomic,strong)PayTypeSelectedButton  * selectedBtn;


@property (nonatomic,strong) UILabel * unReadOrderLab;

@end

@implementation FBPayYHKView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor=[UIColor whiteColor];
        [self createUI];
    }
    return self;
}


-(void)createUI{
    
    _isAgreedXieYi = NO;
    
    //11.000
    UILabel * lab1 = [[UILabel alloc]init];
    [self addSubview:lab1];
    [self setLab:lab1 withColor:RGB(30, 63, 89) andFont:24 andText:@"加载中..." andTextAlignment:NSTextAlignmentCenter];
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(20);
        make.left.equalTo(self.mas_left);
        make.height.equalTo(@(30));
        make.width.equalTo(@(G_SCREENWIDTH));
    }];
    _lab1=lab1;
    //壹拾壹元整
    UILabel * lab2 = [[UILabel alloc]init];
    [self addSubview:lab2];
    [self setLab:lab2 withColor:RGB(30, 63, 89) andFont:12 andText:@"加载中..." andTextAlignment:NSTextAlignmentCenter];
    [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab1.mas_bottom).offset(0);
        make.left.equalTo(self.mas_left);
        make.height.equalTo(@(30));
        make.width.equalTo(@(G_SCREENWIDTH));
    }];
    
    _lab2=lab2;
    UIImageView * timeimgV=[[UIImageView alloc]init];
    [self addSubview:timeimgV];
    timeimgV.image=[UIImage imageNamed:@"时间icon"];
    [timeimgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset((G_SCREENWIDTH-150)/2.0);
        make.top.equalTo(lab2.mas_bottom).offset(10);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(15);
    }];
    
    UILabel * lab3 = [[UILabel alloc]init];
    [self addSubview:lab3];
    [self setLab:lab3 withColor:[UIColor redColor] andFont:12 andText:@"加载中..." andTextAlignment:NSTextAlignmentLeft];
    [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(timeimgV.mas_centerY).offset(0);
        make.left.equalTo(timeimgV.mas_right).offset(10);
        make.height.equalTo(@(30));
        //        make.width.equalTo(@(G_SCREENWIDTH));
    }];
    _lab3=lab3;
    
    UILabel * time = [[UILabel alloc]init];
    [self addSubview:time];
    [self setLab:time withColor:RGB(30, 63, 89) andFont:12 andText:@"加载中" andTextAlignment:NSTextAlignmentLeft];
    [time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(timeimgV.mas_centerY).offset(0);
        make.left.equalTo(lab3.mas_right).offset(10);
        make.height.mas_equalTo(30);
        //        make.width.mas_equalTo(100);
    }];
    _time=time;
    
    PayTypeSelectedButton  * selectedBtn = [[PayTypeSelectedButton alloc]init];
    [self addSubview:selectedBtn];
    _selectedBtn=selectedBtn;
    selectedBtn.logo.image=[UIImage imageNamed:@"微信-3"];
    selectedBtn.lab.text = @"微信";
    selectedBtn.imgVselected.hidden=YES;
    [selectedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(30));
        make.left.equalTo(self.mas_left).offset(0);
        make.right.equalTo(self.mas_right).offset(0);
        make.top.equalTo(timeimgV.mas_bottom).offset(15);
    }];
    
    UILabel * lab4 = [[UILabel alloc]init];
    UILabel * lab5 = [[UILabel alloc]init];
    UILabel * lab6 = [[UILabel alloc]init];

    _lab4=lab4;
    _lab5=lab5;
    _lab6=lab6;
    [self setLeftText:@"真实姓名" andLab:lab4 andIndex:0];
    [self setLeftText:@"开户银行" andLab:lab5 andIndex:1];
    [self setLeftText:@"银行卡号" andLab:lab6 andIndex:2];

   
  
    
    UIView * line = [[UIView alloc]init];
    [self addSubview:line];
    line.backgroundColor=RGB(232, 234, 237);
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab6.mas_bottom).offset(10);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo(G_SCREENWIDTH-30);
        make.height.mas_equalTo(1);
    }];
    
    
    UILabel * lab7 = [[UILabel alloc]init];
    [self addSubview:lab7];
    [self setLab:lab7 withColor:RGB(141, 160, 174) andFont:12 andText:@"请在X分X秒内向以上收款方式支付--" andTextAlignment:NSTextAlignmentLeft];
    [lab7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(line.mas_bottom).offset(10);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo(G_SCREENWIDTH-30);
        make.height.mas_equalTo(20);
    }];
    _lab7=lab7;
    UILabel * lab8 = [[UILabel alloc]init];
    [self addSubview:lab8];
    [self setLab:lab8 withColor:RGB(30, 63, 89) andFont:12 andText:@"在转账的过程当中不要备注任何东西。如有备注将不予放行。若金额大于5000 CNY，法定假日或工作日17:00点以后汇款到银行卡可能造成到账不及时！请分笔付款。" andTextAlignment:NSTextAlignmentLeft];
    [lab8 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab7.mas_bottom).offset(10);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo(G_SCREENWIDTH-30);
        //        make.height.mas_equalTo(20);
    }];
    lab8.numberOfLines=0;
    _lab8=lab8;
    
    UIView * line2 = [[UIView alloc]init];
    [self addSubview:line2];
    line2.backgroundColor=RGB(232, 234, 237);
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab8.mas_bottom).offset(10);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo(G_SCREENWIDTH-30);
        make.height.mas_equalTo(1);
    }];
    
    UIButton * sbtn = [[UIButton alloc]init];
    [self addSubview:sbtn];
    [sbtn setTitleColor:ThemeColor forState:UIControlStateNormal];
    sbtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [sbtn addTarget:self action:@selector(Agreed) forControlEvents:UIControlEventTouchUpInside];
    sbtn.backgroundColor=MC_TEST_COLOR;
    [sbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(30));
        make.width.mas_equalTo(80);
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(line2.mas_bottom).offset(10);
    }];
    
    UIImageView * simgV = [[UIImageView alloc]init];
    [sbtn addSubview:simgV];
    simgV.image = [UIImage imageNamed:@"选择btn-未选中"];
    [simgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(sbtn.mas_centerY).offset(0);
        make.left.equalTo(sbtn.mas_left).offset(0);
        make.width.mas_equalTo(22);
        make.height.mas_equalTo(22);
    }];
    _simgV = simgV;
    
    
    UILabel * lab9 = [[UILabel alloc]init];
    [self addSubview:lab9];
    lab9.numberOfLines = 0;
    [self setLab:lab9 withColor:RGB(141, 160, 174) andFont:13 andText:@"我已知晓：需在付款成功后点击下方按钮。\n(恶意卡单将被冻结账号)" andTextAlignment:NSTextAlignmentLeft];
    [lab9 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-15);
        make.left.equalTo(self.mas_left).offset(15+22+10);
        make.top.equalTo(line2.mas_bottom).offset(15);
        //        make.height.mas_equalTo(22);
    }];
    _lab9=lab9;
    
    
    UIButton *  chat = [[UIButton alloc]init];
    [self addSubview:chat];
    chat.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [chat addTarget:self action:@selector(GoToChatVC) forControlEvents:UIControlEventTouchUpInside];
    [chat setImage:[UIImage imageNamed:@"消息icon"] forState:UIControlStateNormal];
    [chat mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab9.mas_bottom).offset(30);
        make.left.equalTo(self.mas_left).offset(30);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
    UILabel * unReadOrderLab = [[UILabel alloc]init];
    [self addSubview:unReadOrderLab];
    unReadOrderLab.layer.borderColor = [UIColor whiteColor].CGColor;
    unReadOrderLab.layer.borderWidth = 1;
    [self setLab:unReadOrderLab withColor:[UIColor whiteColor] andFont:9 andText:@"" andTextAlignment:NSTextAlignmentCenter];
    unReadOrderLab.layer.cornerRadius = 9;
    unReadOrderLab.clipsToBounds=YES;
    unReadOrderLab.backgroundColor=[UIColor redColor];
    [unReadOrderLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(lab9.mas_bottom).offset(21);
        make.left.equalTo(self.mas_left).offset(40);
        make.width.mas_equalTo(18);
        make.height.mas_equalTo(18);
    }];
    _unReadOrderLab=unReadOrderLab;
    _unReadOrderLab.hidden=YES;
    
    UIButton *  btn2 = [[UIButton alloc]init];
    [self addSubview:btn2];
    btn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [btn2 addTarget:self action:@selector(DidPay) forControlEvents:UIControlEventTouchUpInside];
    [btn2 setTitle:@"已完成付款" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn2.backgroundColor=MC_THEME_COLOR;
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab9.mas_bottom).offset(25);
        make.left.equalTo(chat.mas_right).offset(10);
        //        make.right.equalTo(self.mas_right).offset(-30);
        
        make.width.mas_equalTo(G_SCREENWIDTH-60-20-30);
        make.height.mas_equalTo(40);
    }];
    
    
}

-(void)setDataSource:(FBFindorderModel *)dataSource{
    _dataSource = dataSource;
    
    _lab1.text = [NSString stringWithFormat:@"%@",dataSource.amount];
    _lab2.text = [NSString stringWithFormat:@"%@",dataSource.amount];
    _lab3.text = [FBFindorderTool GetStatusName:dataSource.status andPayType:@""];
    NSDictionary * BankCard = dataSource.BankCard;
    
    if (BankCard) {
        NSDictionary * account = BankCard[@"account"];
        _lab4.text = [NSString stringWithFormat:@"%@",account[@"name"]];
        _lab5.text = [NSString stringWithFormat:@"%@",account[@"create_address"]];
        _lab6.text = [NSString stringWithFormat:@"%@",account[@"card_number"]];
    }
}

-(void)setLeftText:(NSString *)text1 andLab:(UILabel *)lab andIndex:(NSInteger)index {
    CGFloat Top = index* 33 + 10;
    UILabel * left = [[UILabel alloc]init];
    [self addSubview:left];
    [self setLab:left withColor:RGB(140, 159, 173) andFont:13 andText:text1 andTextAlignment:NSTextAlignmentLeft];
    [left mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.selectedBtn.mas_bottom).offset(Top);
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo(self.mas_right).offset(-15);
        make.height.equalTo(@(30));
    }];
    
    
    [self addSubview:lab];
    [self setLab:lab withColor:RGB(30, 63, 89) andFont:13 andText:@"加载中" andTextAlignment:NSTextAlignmentRight];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.selectedBtn.mas_bottom).offset(Top);
        make.width.mas_equalTo(G_SCREENWIDTH-30);
        make.left.equalTo(self.mas_left).offset(15);
        make.height.equalTo(@(30));
    }];
}


-(void)setLab:(UILabel *)lab withColor:(UIColor *)color andFont:(CGFloat)font andText:(NSString *)text andTextAlignment:(NSTextAlignment)textAlignment{
    lab.text=text;
    lab.textColor=color;
    lab.font=[UIFont systemFontOfSize:font];
    lab.textAlignment=textAlignment;
}


-(void)openQRcode{
    if (self.block) {
        self.block(FBFindorderActionType_LookQRcode);
    }
}

-(void)Agreed{
    if (_isAgreedXieYi==NO) {
        _isAgreedXieYi=YES;
        _simgV.image = [UIImage imageNamed:@"选择btn-选中"];
        
    }else{
        
        _isAgreedXieYi=NO;
        _simgV.image = [UIImage imageNamed:@"选择btn-未选中"];
    }
}

-(void)DidPay{
    if (!_isAgreedXieYi) {
        [HUD showErrorMessage:@"请勾选付款规则！"];
        return;
    }
    if (self.block) {
        self.block(FBFindorderActionType_DidPay);
    }
}

-(void)GoToChatVC{
    if (self.block) {
        self.block(FBFindorderActionType_GoToChat);
    }
}

-(void)setSTime:(NSString *)sTime{
    
    _time.text = sTime;
    _lab7.text = [NSString stringWithFormat:@"请在%@内向以上收款方式支付%@",sTime,_dataSource.amount];
    
}


#pragma mark-设置未读消息数量
-(void)setUnReadOrderNum{
    
    FBFindorderUnReadOrder * FU = [FBFindorderUnReadOrder sharedFBFindorderUnReadOrder];
    NSLog(@"%@",self.dataSource.order_sn);
    NSString * order_sn = [NSString stringWithFormat:@"%@",self.dataSource.order_sn];
    NSString * Num = [NSString stringWithFormat:@"%@",FU.UnReadOrderDic[order_sn]];
    if ([Num integerValue]>0) {
        _unReadOrderLab.text=Num;
        _unReadOrderLab.hidden=NO;
        if ([Num integerValue]<10) {
            _unReadOrderLab.font = [UIFont boldSystemFontOfSize:9];
        }
    }else{
        _unReadOrderLab.hidden=YES;
    }
    
}
@end





